package com.es.www.jdk.advice;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.List;

/**
 * @Created by michangtao
 * @Date 2022/1/26 17:34
 * @Description
 */
@Slf4j
public class LogAdvice implements InvocationHandler {

    private Object targetBean;

    private List<String> methods;

    public LogAdvice(Object targetBean, List<String> methods) {
        this.targetBean = targetBean;
        this.methods = methods;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if(this.methods.contains(method.getName())){
            log.info("信息如下：beanClass：{},method：{},args：{}", targetBean.getClass(),method.getName(),args);
//            System.out.println("beanClass：" + targetBean.getClass() + "," + "method：" + method + "," + "args：" + args);
        }
        return method.invoke(targetBean,args);
    }
}
